var app=getApp()

Page({
  data: {
    hostnumber: '0',
    display: 'none',
    items: [],
    hidden: true
  },
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    // if(options.sessionid!=wx.getStorageSync('sessionid')){
    //   wx.navigateTo({
    //    // url: '/pages/devicelist/devicelist',
    //   })
    // }
    
  },
  onReady: function () {
    // 页面渲染完成
    var that = this;
    wx.request({
      url: 'https://cd.tunnel.litelink.me/v1/smallapp/onlineNumber',
      data:{
         sn:app.globalData.SN
      },
      method: 'GET',
      header: {
        "Content-Type": "application/json"
      },
      success: function (res) {
        
        console.log(res.data);
        console.log(res.data.length);
        //&&res.data.Status=="1"
        if (res.data != null) {
          that.setData({
            hostnumber: res.data.length,
            display: ''
          })
          var list = [];
          for (var i = 0; i < parseInt(res.data.length); i++) {
            console.log(res.data[i].HostName)
            console.log(res.data[i])
            list[i] = { "hostname": res.data[i].HostName, "ipaddr": res.data[i].IPAddress, "macaddr": res.data[i].MACAddress }
          }
          that.setData({
            items: list,
          }),
           wx.showToast({
          title: '加载中',
          icon: 'loading',
          duration: 10000
        }),
          setTimeout(function () {
            wx.hideToast()
        }, 2000)
        }else if(res.statusCode=="404"){
          wx.showToast({
            title: '请稍后再试',
            icon: 'info',
            duration: 2000
          })
        }
      }
      ,
      fail:function(){
         wx.showToast({
            title: '网络故障，请稍后再试',
            icon: 'info',
            duration: 2000
          })
      }
    });
   
  },
  onShow: function () {
    // 页面显示
  },
  onHide: function () {
    // 页面隐藏

  },
  onUnload: function () {
    // 页面关闭
  },
  back: function () {
    console.log("back");
    wx.navigateBack({
      delta: 1
    });
  }
})